/**
 * Created by BIYY on 2018-6-21.
 */
const path = require('path');
const autoprefixer = require('autoprefixer');

const MiniCssExtractPlugin = require('mini-css-extract-plugin');

function resolve(dir) {
  return path.join(__dirname, '..', dir);
}

module.exports = [
  {
    test: /\.jsx?$/,
    use: ['cache-loader','thread-loader', 'babel-loader'],
    include: [resolve('../../src')],
    exclude: [/node_modules/, resolve('../..src/common/lib/react-scoped-style')]
  },
  {
    test: /\.css/,
    use: [
      'cache-loader',
      {
        loader: MiniCssExtractPlugin.loader,
        options: {
          publicPath: '../../'
        }
      },
      {
        loader: 'css-loader',
        options: {}
      }
    ],
    
  },
  {
    test: /\.less$/,
    use: [
      'cache-loader',
      {
        loader: MiniCssExtractPlugin.loader,
        options: {
          publicPath: '../../'
        }
      },
      'thread-loader',
      {
        loader: 'css-loader',
        options: {
          importLoaders: 1,
          modules: true,
          localIdentName: '[name]__[local]-[hash:base64:5]',
          localIndexName: '[name]__[local]___[hash:base64:5]',
        }
      },
      {
        loader: require.resolve('postcss-loader'),
        options: {
          ident: 'postcss',
          plugins: () => [
            require('postcss-flexbugs-fixes'),
            autoprefixer({
              browsers: [
                'last 10 versions',
                'ie >= 6',
                'ie_mob >= 6',
                'ff >= 10',
                'chrome >= 14',
                'safari >= 3',
                'ios >= 4',
                'android >= 4.0'
              ]
            })
          ],
        },
      },
      {
        loader: require.resolve('less-loader'), // compiles Less to CSS
      },
    ],
    
  },
  {
    test: /\.js$/,
    use: ['cache-loader','thread-loader', 'babel-loader'],
    exclude: [/node_modules/],
    include: [resolve('../../src')]
  },
  {
    test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
    loader: 'url-loader',
    query: {
      limit: 10000,
      name: path.posix.join('static', 'img/[name].[ext]'),
    },
    exclude: [/node_modules/],
    include: [resolve('../../src')]
  },
  {
    test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
    loader: 'url-loader?limit=1000000',
    query: {
      limit: 1000,
      name: path.posix.join('static', 'fonts/[name].[ext]')
    },
    include: [resolve('../../src'), resolve('../../node_modules/element-theme-default')]
  },
  {
    test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
    loader: 'url-loader',
    options: {
      limit: 1000,
      name: path.posix.join('static', 'media/[name].[hash:7].[ext]')
    },
    exclude: [/node_modules/],
    include: [resolve('../../src')]
  }
];
